package com.meihua.code.concurrent;

import java.util.Arrays;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @program: leetcode
 * @description:
 * @author: meihua
 * @created: 2021/08/25 10:29
 */
public class ArrayConcurrent {

    public static void main(String[] args) {

        ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 10, TimeUnit.MINUTES, new ArrayBlockingQueue<>(100));
       for (int i=1;i<=10;i++){
           executor.execute(()->{});
       }

        Value<Integer> arr [] = new Value[11];

       for (int i=1;i<=10;i++){
           final  int x=i;
           executor.execute(()->{
               arr[x] = new ArrayConcurrent().new Value(x);
           });
       }

        executor.shutdown();

        System.out.println(Arrays.toString(arr));
    }

    //消除伪共享
    class Value<T> {
        private long p1,p2,p3,p4,p5,p6,p7;
        protected T value;
        private long p9,p10,p11,p12,p13,p14,p15;

        @Override
        public String toString() {
            return String.valueOf(value)  ;
        }

        public Value(T value) {
            this.value = value;
        }
    }

}
